export const squares: GameEntity[] = world.querySelectorAll('#正方形画画纸-1');

import { cubes2 } from './cube2';
squares.forEach((square: GameEntity) => {
    const parent = (() => {
        let parent: GameEntity = cubes2[0];
        cubes2.forEach((cube: GameEntity) => {
            if (
                square.position.distance(cube.position) <
                square.position.distance(parent.position)
            ) {
                parent = cube;
            }
        });
        return parent;
    })();

    const position: GameVector3 = square.position
        .clone()
        .add(new GameVector3(0, parent.position.sub(square.position).y, 0));

    setInterval(async () => {
        for (let i = 0; i < 10; i++) {
            square.position.copy(
                square.position.add(parent.position.sub(position).scale(0.1))
            );
            await sleep(100);
        }
        for (let i = 0; i < 10; i++) {
            square.position.copy(
                square.position.add(position.sub(parent.position).scale(0.1))
            );
            await sleep(100);
        }
    }, 7000);
});
